var multiSelector;
var h;
var w;
var allSelector="";
var recordId;
window.initWave = function () {
	h = document.body.clientHeight;
	w = document.body.clientWidth;
	window.Init();
    var header = document.getElementById('header');
    var src = document.scripts[document.scripts.length-1].baseURI;
    var args = src.substr(src.indexOf("?")+1).split("&");
    for(var i = 0; i<args.length; i++){
        var j =args[i].indexOf("=");
        if(j>-1&&args[i].substr(0,j)=='recordId'){
          recordId = args[i].substr(j+1);
        }
    }
    reusing();
    document.getElementById('spreadright').style.display='block';
    // 通道选择按钮事件
    document.getElementById('tongdao').addEventListener('click', function(event) {
		var str='<div style="line-height:30px;text-align: center"><br>Select the channel:<br><input type="checkbox" id="selectAllBox" onclick="selectAll()"/>Select all<br>';
		for(var i=0;i<allSelector.length;i++){
			if(allSelector[i]["status"]=="selected")
				str+='<input id="tdcheckbox'+i+'" type="checkbox" checked="true" />';
			else
				str+='<input id="tdcheckbox'+i+'" type="checkbox" />';
	 		str+=allSelector[i]["text"]+"<br>";
		}
		str+="<br><span class='button white' onclick='tongdaoSubmit()'>&nbsp;Submit&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='button white' onclick='tongdaoCancel()'>&nbsp;Cancel&nbsp;</span></div><br><br><br>";
		document.getElementById("abc").style.display="none";
		document.getElementById("cba").innerHTML=str;
		document.getElementById("cba").style.display="block";
	})
}

function reusing(){
	var str='[';
	if(allSelector!="")
	for(var i=0;i<allSelector.length;i++){
		str+='{"status":"'+allSelector[i]["status"]+'","text":"'+allSelector[i]["text"]+'"},'
		}
	if(str.length!=1)
    	str=str.substring(0,str.length-1);
	str+=']';
	allSelector =str;
	var ret = json;
    if(ret){
    	if(ret.allSelector){
    		allSelector = ret.allSelector;
    	}else{
    		alert("error");
    	}
		drawCanvas(ret);
	}
	else{
		alert(url+'error');
	}
}
function drawCanvas(data){
  	Interface(data);
}
function tongdaoCancel(){
	document.getElementById("goTop").click();
	document.getElementById("abc").style.display="block";
	document.getElementById("cba").style.display="none";
}
function selectAll(){
	var selectAllBox = document.getElementById("selectAllBox");
	if(selectAllBox.checked){
		for(var i=0;i<allSelector.length;i++){
			document.getElementById("tdcheckbox"+i).checked="true";
		}
	}else{
		for(var i=0;i<allSelector.length;i++){
			document.getElementById("tdcheckbox"+i).checked="";
		}
	}
}
function tongdaoSubmit(){
	for(var i=0;i<allSelector.length;i++){
		if(document.getElementById("tdcheckbox"+i).checked){
			allSelector[i]["status"]="selected";
		}else{
			allSelector[i]["status"]="normal";
		}
	}
	reusing();
	tongdaoCancel();
	document.getElementById('div').scrollTop = 0;
}

 
